<template>
    <view style="padding: 15px;">
        <u-form ref="validateFormRef" :model="validateForm.value" :label-width="150">
            <u-form-item label="充值金额" prop="payMoney" required>
                <u-input v-model="validateForm.value.payMoney" placeholder="请输入大于0的整数金额，单位元"/>
            </u-form-item>
        </u-form>

        <u-button type="error" @click="submit">提交</u-button>
    </view>
</template>

<script>

    import {initPayEnvironment, pay_tbStoreCashDeposit} from "../../../../../../dev/core/utils/pay";
    import {CommonUtil} from "../../../../../../dev/core/utils/common.util";

    export default {
        data() {
            return {
                validateForm: {
                    value: {
                        payMoney: '100',
                    },
                    rules: {
                        payMoney: [
                            {required: true, message: '必填项!', trigger: ['change', 'blur']},
                            {pattern: /^\+?[1-9][0-9]*$/, message: '请输入大于0的整数金额，单位元!', trigger: ['change', 'blur']}
                        ],
                    }
                }
            }
        },
        onReady() {
            const _self = this;
        },
        methods: {
            submit() {
                const _self = this;
                this.$refs.validateFormRef.validate(valid => {
                    if (valid) {
                        console.log('验证通过', _self.validateForm.value);
                        CommonUtil.alert({
                            title: '提示！',
                            content: '确认充值吗？',
                            showCancel: true, // 是否显示取消按钮
                            success: function (res) {
                                if (res.cancel) { // 点击取消,默认隐藏弹框
                                } else { // 点击确定
                                    initPayEnvironment().then(result => {
                                        pay_tbStoreCashDeposit({
                                            payMoney: _self.validateForm.value.payMoney,
                                            callback: function (result) {
                                                if (result) {
                                                    CommonUtil.toastNavigateBack();
                                                }
                                            }
                                        })
                                    });
                                }
                            }
                        });
                    } else {
                        console.log('验证失败');
                    }
                });
            }
        }
    };
</script>

<style lang="scss" scoped>
</style>
